package com.itboye.lottery.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.bylibrary.widget.glide.GlideUtil;
import com.itboye.lottery.R;
import com.itboye.lottery.activity.MyAttentionActivity;
import com.itboye.lottery.bean.UserDataBean;

import java.util.ArrayList;

/**
 * Created by wu on 2018/1/9.
 */

public class MyAttentionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Activity activity;
    private Context context;
    ArrayList<UserDataBean> classEntityArrayList = new ArrayList<>();
    private int follow;

    public MyAttentionAdapter(Activity activity, ArrayList<UserDataBean> classEntityArrayList) {
        this.classEntityArrayList = classEntityArrayList;
        this.activity = activity;
    }

    public OnItemClickListener itemClickListener;

    public void setOnItemClickListener(MyAttentionAdapter.OnItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    public void setFollow(int follow) {
        this.follow=follow;
    }


    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_my_attention, parent, false));
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        UserDataBean userDataBean = classEntityArrayList.get(position);
        ViewHolder viewHolder = ((ViewHolder) holder);
//        String title = hash.get("title").toString();
//        String content = hash.get("content").toString();
//        int resource = Integer.parseInt(hash.get("icon").toString());
//        ((ViewHolderFind) holder).title.setText(title);
//        ((ViewHolderFind) holder).content.setText(content);
//        ((ViewHolderFind) holder).icon.setBackgroundResource(resource);
        if (userDataBean != null) {
            GlideUtil.displayForCircle(context, userDataBean.getHead_pic(), viewHolder.iv_item_attention_user_head);
            viewHolder.tv_item_attention_user_name.setText(userDataBean.getNickname());
            if (follow==0) {//是我的关注
                viewHolder.tv_item_attention_click.setVisibility(View.VISIBLE);
                viewHolder.tv_item_attention_click.setTag(position);
                viewHolder.tv_item_attention_click.setOnClickListener((MyAttentionActivity) activity);
            }else {//是我的粉丝
                viewHolder.tv_item_attention_click.setVisibility(View.GONE);
            }
        }
//        holder.name.setText(list.get(position).getClassification_name());
    }

    @Override
    public int getItemCount() {
        return classEntityArrayList == null ? 0 : classEntityArrayList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        public ImageView iv_item_attention_user_head;
        public TextView tv_item_attention_user_name;
        public TextView tv_item_attention_click;

        public ViewHolder(View itemView) {
            super(itemView);
            iv_item_attention_user_head = itemView.findViewById(R.id.iv_item_attention_user_head);
            tv_item_attention_user_name = itemView.findViewById(R.id.tv_item_attention_user_name);
            tv_item_attention_click = itemView.findViewById(R.id.tv_item_attention_click);
//
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (itemClickListener != null) {
                itemClickListener.onItemClick(v, getAdapterPosition());
            }
        }
    }

}
